#[cfg(windows)]
fn embed_icon() {
    use winres::WindowsResource;
    let mut res = WindowsResource::new();
    res.set_icon("assets/icon.ico");
    res.set("OriginalFilename", "sedentary-reminder.exe");
    res.set("FileDescription", "Sedentary Reminder");
    res.compile().unwrap();
}

fn main() {
    println!("cargo:rerun-if-changed=.env",);
    let dotpath = dotenvy::dotenv();

    if dotpath.is_ok() {
        for env_var in dotenvy::dotenv_iter().unwrap() {
            let (key, value) = env_var.unwrap();
            println!("cargo:rustc-env={key}={value}");
        }
    }

    #[cfg(all(windows, target_env = "msvc"))]
    {
        println!("cargo:rustc-link-arg=/SUBSYSTEM:WINDOWS");
        println!("cargo:rustc-link-arg=/ENTRY:mainCRTStartup");
    }

    #[cfg(all(windows, target_env = "gnu"))]
    {
        println!("cargo:rustc-link-arg=-Wl,--subsystem,windows");
    }

    #[cfg(windows)]
    {
        // embed icon
        embed_icon();
    }
}
